package cn.itsource.basic.service.impl;

import cn.itsource.basic.mapper.BaseMapper;
import cn.itsource.basic.query.BaseQuery;
import cn.itsource.basic.service.BaseService;
import cn.itsource.basic.util.PageResult;
import cn.itsource.pet.domain.Pet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service

public class BaseImpl<T> implements BaseService<T> {
    @Autowired
    BaseMapper<T> baseMapper;

    @Override
    @Transactional
    public void insert(T t) {
        baseMapper.insert(t);
        /*        addDirPath(t);*/
    }

    @Override
    @Transactional
    public void delete(Long id) {
        baseMapper.delete(id);
    }

    @Override
    @Transactional
    public void update(T t) {
        baseMapper.update(t);
        /*        addDirPath(t);*/
    }

    @Override
    public T selectById(Long id) {
        return baseMapper.selectById(id);
    }

    @Override
    public List<T> selectAll() {
        return baseMapper.selectAll();
    }

    @Override
    @Transactional
    public void patchDelete(List<Long> ids) {
        baseMapper.patchDelete(ids);
    }

    @Override
    public PageResult<T> selectByQueryPage(BaseQuery query) {
        Integer totals = baseMapper.QueryCount(query);
        List<T> list = (List<T>) baseMapper.QueryData(query);
        return new PageResult<T>(totals, list);
    }
}
